<template>
	<view>
		<view style="display: flex;">
			<u-avatar :src="Avatar" size="60"></u-avatar>
			<span style="margin-top: 14px; margin-left: 10px;">{{Name}}{{Cellphone}}</span>
		</view>		
		<u-list v-if="allcount!=0">
			<u-list-item v-if="todocounts['8']">
				<u-cell title="工程审批" @click="openPage('todo?flowid=8')">
					<!-- <view slot="label" style="font-size: 12px;color: #909193;line-height: 18px;">
						<span>{{'车牌号:' + (item.CarNo || '') + ' 型号:' + (item.Model || '') + ' 状态:'}}</span>
					</view> -->
					<view slot="right-icon">
						<u-badge max="99" :value="todocounts['8']||0"></u-badge>
					</view>
					<u-avatar slot="icon" shape="square" size="40"
						src="https://project.gxrunxiang.com/cdn/picker.png"
						customStyle="margin: -3px 5px -3px 0"></u-avatar>
				</u-cell>
			</u-list-item>
			<u-list-item v-if="todocounts['10']">
				<u-cell title="工程验收" @click="openPage('buildlistForFinish')">
					<!-- <view slot="label" style="font-size: 12px;color: #909193;line-height: 18px;">
						<span>{{'车牌号:' + (item.CarNo || '') + ' 型号:' + (item.Model || '') + ' 状态:'}}</span>
					</view> -->
					<view slot="right-icon">
						<u-badge max="99" :value="todocounts['10']||0"></u-badge>
					</view>
					<u-avatar slot="icon" shape="square" size="40"
						src="https://project.gxrunxiang.com/cdn/checkbox.png"
						customStyle="margin: -3px 5px -3px 0"></u-avatar>
				</u-cell>
			</u-list-item>
			<!-- <u-list-item v-if="buildcount['待派工']">
				<u-cell title="工程派工" @click="openPage('sendwork/buildlist')">
					<view slot="label" style="font-size: 12px;color: #909193;line-height: 18px;">
						<span>{{'车牌号:' + (item.CarNo || '') + ' 型号:' + (item.Model || '') + ' 状态:'}}</span>
					</view>
					<view slot="right-icon">
						<u-badge max="99" :value="buildcount['待派工']"></u-badge>
					</view>
					<u-avatar slot="icon" shape="square" size="40"
						src="https://project.gxrunxiang.com/cdn/top.png"
						customStyle="margin: -3px 5px -3px 0"></u-avatar>
				</u-cell>
			</u-list-item> -->
			<u-list-item v-if="todocounts['7']">
				<u-cell title="工程变更" @click="openPage('todo?flowid=7')">
					<!-- <view slot="label" style="font-size: 12px;color: #909193;line-height: 18px;">
						<span>{{'车牌号:' + (item.CarNo || '') + ' 型号:' + (item.Model || '') + ' 状态:'}}</span>
					</view> -->
					<view slot="right-icon">
						<u-badge max="99" :value="todocounts['7']||0"></u-badge>
					</view>
					<u-avatar slot="icon" shape="square" size="40"
						src="https://project.gxrunxiang.com/cdn/parse.png"
						customStyle="margin: -3px 5px -3px 0"></u-avatar>
				</u-cell>
			</u-list-item>
			<u-list-item v-if="todocounts['5']">
				<u-cell title="工程整改" @click="openPage('buildputright/list')">
					<!-- <view slot="label" style="font-size: 12px;color: #909193;line-height: 18px;">
						<span>{{'车牌号:' + (item.CarNo || '') + ' 型号:' + (item.Model || '') + ' 状态:'}}</span>
					</view> -->
					<view slot="right-icon">
						<u-badge max="99" :value="todocounts['5']||0"></u-badge>
					</view>
					<u-avatar slot="icon" shape="square" size="40"
						src="https://project.gxrunxiang.com/cdn/transition.png"
						customStyle="margin: -3px 5px -3px 0"></u-avatar>
				</u-cell>
			</u-list-item>
			<u-list-item v-if="todocounts['2']">
				<u-cell title="总部立项" @click="openPage('todo?flowid=2')">
					<!-- <view slot="label" style="font-size: 12px;color: #909193;line-height: 18px;">
						<span>{{'车牌号:' + (item.CarNo || '') + ' 型号:' + (item.Model || '') + ' 状态:'}}</span>
					</view> -->
					<view slot="right-icon">
						<u-badge max="99" :value="todocounts['2']||0"></u-badge>
					</view>
					<u-avatar slot="icon" shape="square" size="40"
						src="https://project.gxrunxiang.com/cdn/form.png"
						customStyle="margin: -3px 5px -3px 0"></u-avatar>
				</u-cell>
			</u-list-item>
			<u-list-item v-if="todocounts['1237a83b-b813-437c-a5ef-b9302aaf2768']">
				<u-cell title="分公司立项" @click="openPage('todo?flowid=1237a83b-b813-437c-a5ef-b9302aaf2768')">
					<!-- <view slot="label" style="font-size: 12px;color: #909193;line-height: 18px;">
						<span>{{'车牌号:' + (item.CarNo || '') + ' 型号:' + (item.Model || '') + ' 状态:'}}</span>
					</view> -->
					<view slot="right-icon">
						<u-badge max="99" :value="todocounts['1237a83b-b813-437c-a5ef-b9302aaf2768']||0"></u-badge>
					</view>
					<u-avatar slot="icon" shape="square" size="40"
						src="https://project.gxrunxiang.com/cdn/proj2.png"
						customStyle="margin: -3px 5px -3px 0"></u-avatar>
				</u-cell>
			</u-list-item>
			<u-list-item v-if="todocounts['4']">
				<u-cell title="项目延期" @click="openPage('todo?flowid=4')">
					<!-- <view slot="label" style="font-size: 12px;color: #909193;line-height: 18px;">
						<span>{{'车牌号:' + (item.CarNo || '') + ' 型号:' + (item.Model || '') + ' 状态:'}}</span>
					</view> -->
					<view slot="right-icon">
						<u-badge max="99" :value="todocounts['4']||0"></u-badge>
					</view>
					<u-avatar slot="icon" shape="square" size="40"
						src="https://project.gxrunxiang.com/cdn/alert.png"
						customStyle="margin: -3px 5px -3px 0"></u-avatar>
				</u-cell>
			</u-list-item>
			<u-list-item v-if="todocounts['11']">
				<u-cell title="总部项目竣工" @click="openPage('todo?flowid=11')">
					<!-- <view slot="label" style="font-size: 12px;color: #909193;line-height: 18px;">
						<span>{{'车牌号:' + (item.CarNo || '') + ' 型号:' + (item.Model || '') + ' 状态:'}}</span>
					</view> -->
					<view slot="right-icon">
						<u-badge max="99" :value="todocounts['11']||0"></u-badge>
					</view>
					<u-avatar slot="icon" shape="square" size="40"
						src="https://project.gxrunxiang.com/cdn/checkbox.png"
						customStyle="margin: -3px 5px -3px 0"></u-avatar>
				</u-cell>
			</u-list-item>
			<u-list-item v-if="todocounts['a3bf67c0-8957-4e28-983a-b2608cfe2869']">
				<u-cell title="分公司项目竣工" @click="openPage('todo?flowid=11')">
					<!-- <view slot="label" style="font-size: 12px;color: #909193;line-height: 18px;">
						<span>{{'车牌号:' + (item.CarNo || '') + ' 型号:' + (item.Model || '') + ' 状态:'}}</span>
					</view> -->
					<view slot="right-icon">
						<u-badge max="99" :value="todocounts['a3bf67c0-8957-4e28-983a-b2608cfe2869']||0"></u-badge>
					</view>
					<u-avatar slot="icon" shape="square" size="40"
						src="https://project.gxrunxiang.com/cdn/checkBox2.png"
						customStyle="margin: -3px 5px -3px 0"></u-avatar>
				</u-cell>
			</u-list-item>
			<u-list-item v-if="todocounts['3']">
				<u-cell title="项目变更" @click="openPage('todo?flowid=3')">
					<!-- <view slot="label" style="font-size: 12px;color: #909193;line-height: 18px;">
						<span>{{'车牌号:' + (item.CarNo || '') + ' 型号:' + (item.Model || '') + ' 状态:'}}</span>
					</view> -->
					<view slot="right-icon">
						<u-badge max="99" :value="todocounts['3']||0"></u-badge>
					</view>
					<u-avatar slot="icon" shape="square" size="40"
						src="https://project.gxrunxiang.com/cdn/parse.png"
						customStyle="margin: -3px 5px -3px 0"></u-avatar>
				</u-cell>
			</u-list-item>
			<u-list-item v-if="todocounts['维护工单']">
				<u-cell title="维护工单" @click="openPage('Protect/fault')">
					<!-- <view slot="label" style="font-size: 12px;color: #909193;line-height: 18px;">
						<span>{{'车牌号:' + (item.CarNo || '') + ' 型号:' + (item.Model || '') + ' 状态:'}}</span>
					</view> -->
					<view slot="right-icon">
						<u-badge max="99" :value="todocounts['维护工单']||0"></u-badge>
					</view>
					<u-avatar slot="icon" shape="square" size="40"
						src="https://project.gxrunxiang.com/cdn/fault.png"
						customStyle="margin: -3px 5px -3px 0"></u-avatar>
				</u-cell>
			</u-list-item>
			<u-list-item v-if="buildcount['用车申请']">
				<u-cell title="用车审批" @click="openPage('Car/carapply')">
					<!-- <view slot="label" style="font-size: 12px;color: #909193;line-height: 18px;">
						<span>{{'车牌号:' + (item.CarNo || '') + ' 型号:' + (item.Model || '') + ' 状态:'}}</span>
					</view> -->
					<view slot="right-icon">
						<u-badge max="99" :value="buildcount['用车申请']||0"></u-badge>
					</view>
					<u-avatar slot="icon" shape="square" size="40"
						src="https://project.gxrunxiang.com/cdn/carApply.png"
						customStyle="margin: -3px 5px -3px 0"></u-avatar>
				</u-cell>
			</u-list-item>
			<u-list-item v-if="buildcount['用车归还']">
				<u-cell title="用车归还" @click="openPage('Car/carreturn')">
					<!-- <view slot="label" style="font-size: 12px;color: #909193;line-height: 18px;">
						<span>{{'车牌号:' + (item.CarNo || '') + ' 型号:' + (item.Model || '') + ' 状态:'}}</span>
					</view> -->
					<view slot="right-icon">
						<u-badge max="99" :value="buildcount['用车归还']||0"></u-badge>
					</view>
					<u-avatar slot="icon" shape="square" size="40"
						src="https://project.gxrunxiang.com/cdn/carReturn.png"
						customStyle="margin: -3px 5px -3px 0"></u-avatar>
				</u-cell>
			</u-list-item>
			<u-list-item v-if="todocounts['775c5e6e-c7e4-441a-81c2-a242252393d8']">
				<u-cell title="车辆保养审批" @click="openPage('todo?flowid=775c5e6e-c7e4-441a-81c2-a242252393d8')">
					<!-- <view slot="label" style="font-size: 12px;color: #909193;line-height: 18px;">
						<span>{{'车牌号:' + (item.CarNo || '') + ' 型号:' + (item.Model || '') + ' 状态:'}}</span>
					</view> -->
					<view slot="right-icon">
						<u-badge max="99" :value="todocounts['775c5e6e-c7e4-441a-81c2-a242252393d8']||0"></u-badge>
					</view>
					<u-avatar slot="icon" shape="square" size="40"
						src="https://project.gxrunxiang.com/cdn/maintenance.png"
						customStyle="margin: -3px 5px -3px 0"></u-avatar>
				</u-cell>
			</u-list-item>
			<u-list-item v-if="todocounts['入库']">
				<u-cell title="入库申请" @click="openPage('todo?flowid=store')">
					<view slot="right-icon">
						<u-badge max="99" :value="todocounts['入库']||0"></u-badge>
					</view>
					<u-avatar slot="icon" shape="square" size="40"
						src="https://project.gxrunxiang.com/cdn/storein.png"
						customStyle="margin: -3px 5px -3px 0"></u-avatar>
				</u-cell>
			</u-list-item>
			<u-list-item v-if="todocounts['出库']">
				<u-cell title="出库申请" @click="openPage('todo?flowid=store')">
					<view slot="right-icon">
						<u-badge max="99" :value="todocounts['出库']||0"></u-badge>
					</view>
					<u-avatar slot="icon" shape="square" size="40"
						src="https://project.gxrunxiang.com/cdn/storeout.png"
						customStyle="margin: -3px 5px -3px 0"></u-avatar>
				</u-cell>
			</u-list-item>
			<u-list-item v-if="todocounts['调拨']">
				<u-cell title="调拨申请" @click="openPage('todo?flowid=store')">
					<view slot="right-icon">
						<u-badge max="99" :value="todocounts['调拨']||0"></u-badge>
					</view>
					<u-avatar slot="icon" shape="square" size="40"
						src="https://project.gxrunxiang.com/cdn/storecancel.png"
						customStyle="margin: -3px 5px -3px 0"></u-avatar>
				</u-cell>
			</u-list-item>
			<u-list-item v-if="todocounts['退料']">
				<u-cell title="退料申请" @click="openPage('todo?flowid=store')">
					<view slot="right-icon">
						<u-badge max="99" :value="todocounts['退料']||0"></u-badge>
					</view>
					<u-avatar slot="icon" shape="square" size="40"
						src="https://project.gxrunxiang.com/cdn/storeout.png"
						customStyle="margin: -3px 5px -3px 0"></u-avatar>
				</u-cell>
			</u-list-item>
			<!-- <u-loadmore :status="status" v-if="loading" /> -->
		</u-list>
		<u-empty
		        mode="data"
		        
		v-else>
		</u-empty>
	</view>
</template>

<script>
	// import {
	// 	mapMutations,mapGetters
	// } from 'vuex'
	import {
		baseUrl
	} from '@/common/config.js'
	import {
		getbuildcount,
		todocount,
		getFlowRecordList
	} from '@/common/api.js'
	export default {
		data() {
			return {
				year:new Date().getFullYear(),
				month:new Date().getMonth()+1,
				start:'',
				end:'',
				todocounts: {},
				buildcount: {},
				user: [],
				Cellphone: "",
				Roles: "",
				Name: "",
				Avatar: "",
				image: "",
				allcount: ""
			}
		},
		onShow() {
			let user = JSON.parse(uni.getStorageSync("$userinfo"))
			this.user = user
			this.Name = user.Name
			if(user.Avatar)
			this.Avatar = 'data:image/jpg;base64,'+user.Avatar.replace(/[\r\n]/g,'')
			else
			   this.Avatar=null
			this.Roles = user.Roles
			this.Cellphone = user.Cellphone
			this.getbuildcount()
			var allcount = 0
			todocount().then(res => {
				this.todocounts={}
				res.forEach(e => {
					this.todocounts[e.FlowId] = e.count
					allcount += e.count
					if(e.FlowId.includes('入库')){
						this.todocounts['入库'] = (this.todocounts['入库'] ? this.todocounts['入库'] : 0) + e.count
					}
					if(e.FlowId.includes('出库')){
						this.todocounts['出库'] = (this.todocounts['出库'] ? this.todocounts['出库'] : 0) + e.count
					}
					if(e.FlowId.includes('调拨')){
						this.todocounts['调拨'] = (this.todocounts['调拨'] ? this.todocounts['调拨'] : 0) + e.count
					}
					if(e.FlowId.includes('退料')){
						this.todocounts['退料'] = (this.todocounts['退料'] ? this.todocounts['退料'] : 0) + e.count
					}
				})
				this.allcount = allcount
				if (allcount != 0){
					uni.setTabBarBadge({
						index: 0, // 索引
						text: allcount + '' // 注意：text 的值必须是字符串，不能是数字
					})
				}			
			})
		},
		methods: {
			openPage(e) {
				uni.navigateTo({
					url: e
				})
			},
			getbuildcount() {
				getbuildcount(this.start,this.end,this.year,this.month).then(res => {
					this.buildcount = res
				})
			},
			// gomaintenance(){
			// 	let para = {
			// 		Parameters: [],
			// 	}
			// 	para.Parameters.push({
			// 		FieldName: "UseId",
			// 		ConditionalType: "Equal",
			// 		FieldValue: this.user.Id,
			// 	})
			// 	para.Parameters.push({
			// 		FieldName: "FlowId",
			// 		ConditionalType: "Equal",
			// 		FieldValue: '775c5e6e-c7e4-441a-81c2-a242252393d8',
			// 	})
			// 	para.Parameters.push({
			// 		FieldName: "Status",
			// 		ConditionalType: "Like",
			// 		FieldValue: '待办',
			// 	})
			// 	getFlowRecordList(para).then(res => {
			// 		this.openPage('Car/maintenancedetail?Id=' + res.data[0].OutId)
			// 	})
			// }
		}
	}
</script>

<style>

</style>